import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

/// Since: 2024/9/5
/// Author: Elvis.Zhao
/// Version: v1.0
/// Description:

class ImageProcessor {
  static const MethodChannel _channel = MethodChannel('com.example.crop_image_project/asset_channel');

  static Future<String> processImages(String imagePath1, String imagePath2) async {
    try {
      // 读取两个图片为Base64字符串
      final imageBytes1 = await rootBundle.load(imagePath1);
      final imageString1 = base64Encode(imageBytes1.buffer.asUint8List());

      final imageBytes2 = await rootBundle.load(imagePath2);
      final imageString2 = base64Encode(imageBytes2.buffer.asUint8List());

      // 发送Base64字符串到Android
      final result = await _channel.invokeMethod('processImages', {
        'image1': imageString1,
        'image2': imageString2,
      });

      return result;
    } on Exception catch (e) {
      throw Exception('Error processing images: ${e.toString()}');
    }
  }
}
